package com.tetraq.grader;

public class Course {
	private int grading_type;
	private String name;
	Course(int grading_type, String name) {
		this.grading_type = grading_type;
		this.name = name;
	}
	
	public int getType() {
		// 0 means percentage, 1 means point-based
		return grading_type;
	}
	
	public String getName() {
		return name;
	}
	
	public String createTable() {
		if (grading_type == 0)
			return "CREATE TABLE IF NOT EXISTS "
			+ name
			+ " (Grade INT(3), Weight INT(3), Name VARCHAR);";
		else if (grading_type == 1)
			return "CREATE TABLE IF NOT EXISTS "
			+ name
			+ " (Points INT(3), Total INT(3), Grade DOUBLE, Name VARCHAR);";
		else
			return null;
	}
	
	public String addToDatabase(int gradeOrPoints, int weightOrTotal, String name) {
		if (grading_type == 0)
			return "INSERT INTO "
			+ name
			+ " (Grade, Weight, Name)"
			+ " VALUES (" + gradeOrPoints + ", " + weightOrTotal + ", '" + name + "');";
		else if (grading_type == 1)
			return "INSERT INTO "
			+ name
			+ " (Points, Total, Grade, Name)"
			+ " VALUES (" + gradeOrPoints + ", " + weightOrTotal + ", " + (double)gradeOrPoints/weightOrTotal * 100 + ", '" + name + "');";
		else
			return null;
	}
	
	

}
